function checklogin()
{
	$("#error_email").css('display', 'none');
	$("#error_password").css('display', 'none');
	$("#error_email_format").css('display', 'none');
	
	var txtemail	= $("#txtemail").val();
	if (txtemail	== "")
	{
		$("#error_email").css('display', 'block');
		$("#txtemail").focus();
		return false;
	}
	else
	{
		$("#error_email").css('display', 'none');
	}
	
	var atpos	= txtemail.indexOf("@");
    var dotpos	= txtemail.lastIndexOf(".");
   
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=txtemail.length)
    {
    	$("#error_email_format").css('display', 'block');
    	$("#txtemail").focus();
        return false;
    }
    else
    {
    	$("#error_email_format").css('display', 'none');
    }
	
	var txtpassword	= $("#txtpassword").val();
	if (txtpassword	== "")
	{
		$("#error_password").css('display', 'block');
		$("#txtpassword").focus();
		return false;
	}
	else
	{
		$("#error_password").css('display', 'none');
	}
}

var haslogin	= true;
$(document).ready(function() 
{
	$("#email").change(function(e) {
		var base_url	= $('#base_url').val();
		var email		= $("#email").val();
		if (email != "")
		{
			$("#erroremail").css('display', 'none');
			$("#erroremail_format").css('display', 'none');
			$.ajax({
				type: "POST",
				url: base_url + 'check_email',
				data: {email: email},
				dataType: "text",
				beforeSend: function(xhr) 
				{
					xhr.setRequestHeader("Ajax-Request", "true");
				},
				success: function(response) 
				{
					if (response != "")
					{
						$("#td_id").append('<span id="check_email"></span>');
						$("#check_email").html(response);
						haslogin	= false;
						return false;
					}
					else
					{
						haslogin	= true;
						$("#check_email").remove();
					}
				}
			});
		}
		else
		{
			$("#check_email").remove();			
		}
	});	
});
function checkregister()
{
	$("#erroremail").css('display', 'none');
	$("#erroremail_format").css('display', 'none');
	$("#errorpassword").css('display', 'none');	
	$("#errorconfirmpassword").css('display', 'none');
	
	var email	= $("#email").val();
	if (email	== "")
	{
		$("#erroremail").css('display', 'block');
		$("#check_email").remove();
		$("#email").focus();
		return false;
	}
	else
	{
		$("#erroremail").css('display', 'none');
	}
	
	var atpos	= email.indexOf("@");
    var dotpos	= email.lastIndexOf(".");
   
    if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
    {
    	$("#erroremail_format").css('display', 'block');
    	$("#check_email").remove();
    	$("#email").focus();
        return false;
    }
    else
    {
    	$("#erroremail_format").css('display', 'none');
    }
    
    if (haslogin	== false)
    {
    	$("#email").focus();
        return false;
    }
    
    var password	= $("#password").val();
    if (password	== "")
    {
    	$("#errorpassword").css('display', 'block');
    	$("#password").focus();
    	return false;
    }
    else
    {
    	$("#errorpassword").css('display', 'none');
    }
    
    var confirm_password	= $("#confirm_password").val();
	if (password	!= confirm_password)
	{
		$("#errorconfirmpassword").css('display', 'block');
		$("#confirm_password").focus();
		return false;
	}
	else
	{
		$("#errorconfirmpassword").css('display', 'none');
	}
}